//
//  FourthViewController.m
//  Streaming
//
//  Created by 韩一博 on 15/6/27.
//  Copyright (c) 2015年 liuxun. All rights reserved.
//

#import "FourthViewController.h"

@interface FourthViewController ()

@end

@implementation FourthViewController

- (void)dealloc
{
    [self.tableView release];
    
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"流媒体资讯";
    [self.view setBackgroundColor:[UIColor clearColor]];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"我的" style:UIBarButtonItemStyleDone target:self action:@selector(leftBarButtonItemAction)];
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:31/255.0 green:115/255.0 blue:192/255.0 alpha:0.3]];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    [self.tableView release];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    if (indexPath.section == 0) {
        NSMutableArray *arrayName = [NSMutableArray arrayWithObjects:@"清除缓存", @"意见反馈", @"免责声明", @"离线说明",@"关于我们",nil];
        [cell.textLabel setText:[arrayName objectAtIndex:indexPath.row]];
        
    }

    return cell;
    
}

#warning 设置section中的高度和字体
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)] autorelease];
    
    UILabel * headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor blueColor];
    headerLabel.highlightedTextColor = [UIColor yellowColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:25];
    headerLabel.textAlignment = NSTextAlignmentCenter;
    headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);
    
    if (section == 0){
        headerLabel.text = @"设置";
    }
    
    [customView addSubview:headerLabel];
    
    return customView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        NSUInteger size = [[SDImageCache sharedImageCache]getSize];
        CGFloat mb = size / 1024.0 / 1024.0;
        NSString *string = [NSString stringWithFormat:@"当前缓存为%.2fMB", mb];
        NSLog(@"mb = %@", string);
        
        UIAlertView *clearAlert = [[UIAlertView alloc] initWithTitle:string message:@"真的要清除缓存吗?"  delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        
        [clearAlert show];
        [clearAlert release];

        
    }
    if (indexPath.row == 4) {
        ThirdViewController *third = [[ThirdViewController alloc]init];
        [self.navigationController pushViewController:third animated:YES];
        
        [third release];


    }
    if (indexPath.row == 1) {
        UIAlertView *clearAlert2 = [[UIAlertView alloc] initWithTitle:@"意见反馈" message:@"如有问题请告诉我们啊，亲.我的邮箱：1781030315@qq.com"  delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [clearAlert2 show];
        [clearAlert2 release];
    }
    if (indexPath.row == 3) {
        FirstViewController *first = [[FirstViewController alloc]init];
        [self.navigationController pushViewController:first animated:YES];
        
        [first release];
        
        
    }
    if (indexPath.row == 2) {
        SecondViewController *second = [[SecondViewController alloc]init];
        [self.navigationController pushViewController:second animated:YES];
        [second release];
    }


    
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 44.0;
}



- (void)leftBarButtonItemAction
{
    [self.sideMenuViewController presentLeftMenuViewController];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
